package com.hdu.other.tanxin;


import java.util.Arrays;

public class lc781 {

    class Solution {
        public int numRabbits(int[] answers) {
            Arrays.sort(answers);
            int ans = 0;
            int cur = 0;
            while (cur < answers.length)
            {
                int start  = cur;
                while (cur + 1 < answers.length && answers[start] == answers[cur + 1])
                {
                    cur++;
                }
                // cur + 1 == answers.length || answers[start] != answers[cur]
                int len = cur - start + 1;
                int x = answers[start]; // x +1
                int curAns = (len + x + 1 - 1) / (x + 1) * (x + 1);
                ans += curAns;
                cur++;
            }
            return ans;
        }
    }
}
